<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>并发与并行：现代计算的多任务处理之道</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        .serif {
            font-family: 'Noto Serif SC', serif;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .highlight {
            position: relative;
            z-index: 1;
        }
        .highlight::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 30%;
            background-color: rgba(102, 126, 234, 0.2);
            z-index: -1;
            transform: scaleX(1.03);
            transition: all 0.3s ease;
        }
        .highlight:hover::after {
            height: 40%;
            background-color: rgba(102, 126, 234, 0.3);
        }
        .drop-cap::first-letter {
            float: left;
            font-size: 5rem;
            line-height: 0.65;
            margin: 0.1em 0.2em 0 0;
            color: #667eea;
            font-weight: bold;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4 md:py-32">
        <div class="container mx-auto max-w-5xl text-center">
            <h1 class="text-4xl md:text-6xl font-bold mb-6 serif">并发与并行</h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90 max-w-3xl mx-auto">
                现代计算系统中的多任务处理之道
            </p>
            <div class="flex justify-center space-x-4">
                <div class="bg-white text-gray-800 px-6 py-3 rounded-full font-medium inline-flex items-center">
                    <i class="fas fa-brain mr-2 text-purple-600"></i>
                    <span>核心概念</span>
                </div>
                <div class="bg-white bg-opacity-20 text-white px-6 py-3 rounded-full font-medium inline-flex items-center">
                    <i class="fas fa-microchip mr-2"></i>
                    <span>计算原理</span>
                </div>
            </div>
        </div>
    </section>

    <!-- Intro Section -->
    <section class="py-16 px-4">
        <div class="container mx-auto max-w-4xl">
            <div class="bg-white rounded-xl shadow-lg p-8 md:p-12">
                <p class="text-lg md:text-xl text-gray-700 drop-cap">
                    并发（Concurrency）和并行（Parallelism）是计算机科学中描述多任务处理的两个核心概念。它们虽然相关，但有着不同的含义和应用场景。在现代计算机系统中，这两者往往是互补的：并发用于管理任务和提高系统响应能力，并行用于加速计算过程。
                </p>
            </div>
        </div>
    </section>

    <!-- Definition Section -->
    <section class="py-16 px-4 bg-gray-100">
        <div class="container mx-auto max-w-6xl">
            <h2 class="text-3xl md:text-4xl font-bold mb-12 text-center text-gray-800 serif">
                <span class="highlight px-2">定义与区别</span>
            </h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <!-- Concurrency Card -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="bg-purple-600 text-white p-6">
                        <div class="flex items-center">
                            <div class="bg-white bg-opacity-20 p-3 rounded-full mr-4">
                                <i class="fas fa-random text-xl"></i>
                            </div>
                            <h3 class="text-2xl font-bold">并发 (Concurrency)</h3>
                        </div>
                    </div>
                    <div class="p-6">
                        <p class="text-gray-700 mb-4">
                            <span class="font-semibold text-purple-600">定义：</span>
                            在同一时间段内，多个任务在逻辑上同时进行。并发并不要求任务实际同时执行，而是它们可以在不同的时间片段中交替进行。
                        </p>
                        <p class="text-gray-700 mb-4">
                            并发主要关注任务的调度和管理，解决如何在有限的资源上高效地处理多个任务。
                        </p>
                        <div class="bg-purple-50 border-l-4 border-purple-600 p-4 mb-4">
                            <p class="text-gray-700">
                                <span class="font-semibold">例子：</span>
                                在单核处理器上，操作系统通过时间片轮转的方式让多个任务看起来是同时进行的。实际执行时，每个任务会在处理器上占据一定的时间片，然后交换。
                            </p>
                        </div>
                    </div>
                </div>
                
                <!-- Parallelism Card -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="bg-blue-600 text-white p-6">
                        <div class="flex items-center">
                            <div class="bg-white bg-opacity-20 p-3 rounded-full mr-4">
                                <i class="fas fa-sliders-h text-xl"></i>
                            </div>
                            <h3 class="text-2xl font-bold">并行 (Parallelism)</h3>
                        </div>
                    </div>
                    <div class="p-6">
                        <p class="text-gray-700 mb-4">
                            <span class="font-semibold text-blue-600">定义：</span>
                            多个任务在物理上同时执行。并行要求任务可以真正同时进行，通常需要多核处理器或多台计算机。
                        </p>
                        <p class="text-gray-700 mb-4">
                            并行关注的是如何在多个处理单元上同时执行任务，以提高计算效率。
                        </p>
                        <div class="bg-blue-50 border-l-4 border-blue-600 p-4 mb-4">
                            <p class="text-gray-700">
                                <span class="font-semibold">例子：</span>
                                在多核处理器上，多个核心可以同时执行不同的任务或同一任务的不同部分，从而提高计算速度。
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Visualization Section -->
    <section class="py-16 px-4">
        <div class="container mx-auto max-w-6xl">
            <h2 class="text-3xl md:text-4xl font-bold mb-12 text-center text-gray-800 serif">
                <span class="highlight px-2">概念关系可视化</span>
            </h2>
            
            <div class="bg-white rounded-xl shadow-md p-6 md:p-8">
                <div class="mermaid">
                    flowchart TD
                        A[多任务处理] --> B[并发 Concurrency]
                        A --> C[并行 Parallelism]
                        B --> D[逻辑上的同时]
                        B --> E[任务调度与管理]
                        B --> F[单核处理器]
                        C --> G[物理上的同时]
                        C --> H[计算效率提升]
                        C --> I[多核处理器]
                </div>
            </div>
        </div>
    </section>

    <!-- Goals Section -->
    <section class="py-16 px-4 bg-gray-100">
        <div class="container mx-auto max-w-6xl">
            <h2 class="text-3xl md:text-4xl font-bold mb-12 text-center text-gray-800 serif">
                <span class="highlight px-2">目标与用途</span>
            </h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-md p-8">
                    <div class="flex items-center mb-6">
                        <div class="bg-purple-100 p-3 rounded-full mr-4">
                            <i class="fas fa-bullseye text-purple-600 text-xl"></i>
                        </div>
                        <h3 class="text-2xl font-bold text-gray-800">并发的目标</h3>
                    </div>
                    <p class="text-gray-700 mb-4">
                        提高系统的响应能力和资源利用率，通过合理的任务调度和切换来管理多个任务。
                    </p>
                    <p class="text-gray-700">
                        关注如何有效地管理多个任务，确保系统能够处理多个任务而不会因为一个任务的延迟影响到其他任务。
                    </p>
                </div>
                
                <div class="bg-white rounded-xl shadow-md p-8">
                    <div class="flex items-center mb-6">
                        <div class="bg-blue-100 p-3 rounded-full mr-4">
                            <i class="fas fa-tachometer-alt text-blue-600 text-xl"></i>
                        </div>
                        <h3 class="text-2xl font-bold text-gray-800">并行的目标</h3>
                    </div>
                    <p class="text-gray-700 mb-4">
                        提高计算性能和效率，通过同时执行多个任务来加速处理速度。
                    </p>
                    <p class="text-gray-700">
                        关注如何利用硬件资源（如多核处理器）来同时执行任务，从而减少总的计算时间。
                    </p>
                </div>
            </div>
        </div>
    </section>

    <!-- Implementation Section -->
    <section class="py-16 px-4">
        <div class="container mx-auto max-w-6xl">
            <h2 class="text-3xl md:text-4xl font-bold mb-12 text-center text-gray-800 serif">
                <span class="highlight px-2">实现方式</span>
            </h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="bg-purple-600 text-white p-6">
                        <div class="flex items-center">
                            <div class="bg-white bg-opacity-20 p-3 rounded-full mr-4">
                                <i class="fas fa-code text-xl"></i>
                            </div>
                            <h3 class="text-2xl font-bold">并发的实现</h3>
                        </div>
                    </div>
                    <div class="p-6">
                        <ul class="space-y-4">
                            <li class="flex items-start">
                                <div class="bg-purple-100 p-1 rounded-full mr-3 mt-1">
                                    <i class="fas fa-check text-purple-600 text-xs"></i>
                                </div>
                                <span class="text-gray-700">操作系统的调度机制、线程或进程的切换</span>
                            </li>
                            <li class="flex items-start">
                                <div class="bg-purple-100 p-1 rounded-full mr-3 mt-1">
                                    <i class="fas fa-check text-purple-600 text-xs"></i>
                                </div>
                                <span class="text-gray-700">语言层面的并发支持（如 Java 的线程、C# 的任务并行库）</span>
                            </li>
                            <li class="flex items-start">
                                <div class="bg-purple-100 p-1 rounded-full mr-3 mt-1">
                                    <i class="fas fa-check text-purple-600 text-xs"></i>
                                </div>
                                <span class="text-gray-700">操作系统提供的并发工具（如线程、进程）</span>
                            </li>
                        </ul>
                    </div>
                </div>
                
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="bg-blue-600 text-white p-6">
                        <div class="flex items-center">
                            <div class="bg-white bg-opacity-20 p-3 rounded-full mr-4">
                                <i class="fas fa-cogs text-xl"></i>
                            </div>
                            <h3 class="text-2xl font-bold">并行的实现</h3>
                        </div>
                    </div>
                    <div class="p-6">
                        <ul class="space-y-4">
                            <li class="flex items-start">
                                <div class="bg-blue-100 p-1 rounded-full mr-3 mt-1">
                                    <i class="fas fa-check text-blue-600 text-xs"></i>
                                </div>
                                <span class="text-gray-700">多核处理器、分布式计算</span>
                            </li>
                            <li class="flex items-start">
                                <div class="bg-blue-100 p-1 rounded-full mr-3 mt-1">
                                    <i class="fas fa-check text-blue-600 text-xs"></i>
                                </div>
                                <span class="text-gray-700">并行算法和框架（如 CUDA、OpenMP）</span>
                            </li>
                            <li class="flex items-start">
                                <div class="bg-blue-100 p-1 rounded-full mr-3 mt-1">
                                    <i class="fas fa-check text-blue-600 text-xs"></i>
                                </div>
                                <span class="text-gray-700">需要确保任务可以分割成子任务并且可以独立执行</span>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Use Cases Section -->
    <section class="py-16 px-4 bg-gray-100">
        <div class="container mx-auto max-w-6xl">
            <h2 class="text-3xl md:text-4xl font-bold mb-12 text-center text-gray-800 serif">
                <span class="highlight px-2">应用场景</span>
            </h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-md p-8">
                    <div class="flex items-center mb-6">
                        <div class="bg-purple-100 p-3 rounded-full mr-4">
                            <i class="fas fa-server text-purple-600 text-xl"></i>
                        </div>
                        <h3 class="text-2xl font-bold text-gray-800">并发的应用</h3>
                    </div>
                    <p class="text-gray-700 mb-4">
                        适用于需要管理多个任务或处理多个请求的系统，如：
                    </p>
                    <ul class="space-y-3">
                        <li class="flex items-start">
                            <div class="bg-purple-100 p-1 rounded-full mr-3 mt-1">
                                <i class="fas fa-globe text-purple-600 text-xs"></i>
                            </div>
                            <span class="text-gray-700">Web 服务器（同时处理多个客户端请求）</span>
                        </li>
                        <li class="flex items-start">
                            <div class="bg-purple-100 p-1 rounded-full mr-3 mt-1">
                                <i class="fas fa-database text-purple-600 text-xs"></i>
                            </div>
                            <span class="text-gray-700">数据库系统</span>
                        </li>
                        <li class="flex items-start">
                            <div class="bg-purple-100 p-1 rounded-full mr-3 mt-1">
                                <i class="fas fa-mobile-alt text-purple-600 text-xs"></i>
                            </div>
                            <span class="text-gray-700">用户界面系统（保持UI响应）</span>
                        </li>
                    </ul>
                </div>
                
                <div class="bg-white rounded-xl shadow-md p-8">
                    <div class="flex items-center mb-6">
                        <div class="bg-blue-100 p-3 rounded-full mr-4">
                            <i class="fas fa-rocket text-blue-600 text-xl"></i>
                        </div>
                        <h3 class="text-2xl font-bold text-gray-800">并行的应用</h3>
                    </div>
                    <p class="text-gray-700 mb-4">
                        适用于计算密集型任务，需要大量计算的场景，如：
                    </p>
                    <ul class="space-y-3">
                        <li class="flex items-start">
                            <div class="bg-blue-100 p-1 rounded-full mr-3 mt-1">
                                <i class="fas fa-flask text-blue-600 text-xs"></i>
                            </div>
                            <span class="text-gray-700">科学计算</span>
                        </li>
                        <li class="flex items-start">
                            <div class="bg-blue-100 p-1 rounded-full mr-3 mt-1">
                                <i class="fas fa-image text-blue-600 text-xs"></i>
                            </div>
                            <span class="text-gray-700">图像处理</span>
                        </li>
                        <li class="flex items-start">
                            <div class="bg-blue-100 p-1 rounded-full mr-3 mt-1">
                                <i class="fas fa-chart-bar text-blue-600 text-xs"></i>
                            </div>
                            <span class="text-gray-700">大数据分析</span>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </section>

    <!-- Summary Section -->
    <section class="py-16 px-4">
        <div class="container mx-auto max-w-4xl">
            <div class="bg-gradient-to-r from-purple-500 to-blue-500 rounded-xl shadow-lg p-8 md:p-12 text-white">
                <div class="flex items-center mb-6">
                    <div class="bg-white bg-opacity-20 p-3 rounded-full mr-4">
                        <i class="fas fa-lightbulb text-xl"></i>
                    </div>
                    <h3 class="text-2xl md:text-3xl font-bold">关键总结</h3>
                </div>
                <p class="text-lg md:text-xl opacity-90 mb-4">
                    在现代计算机系统中，并发和并行往往是<strong>互补</strong>的：
                </p>
                <ul class="space-y-3 text-lg opacity-90">
                    <li class="flex items-start">
                        <div class="bg-white bg-opacity-20 p-1 rounded-full mr-3 mt-1">
                            <i class="fas fa-check text-xs"></i>
                        </div>
                        <span>并发用于<strong>管理任务</strong>和提高<strong>系统响应能力</strong></span>
                    </li>
                    <li class="flex items-start">
                        <div class="bg-white bg-opacity-20 p-1 rounded-full mr-3 mt-1">
                            <i class="fas fa-check text-xs"></i>
                        </div>
                        <span>并行用于<strong>加速计算过程</strong>和提高<strong>处理效率</strong></span>
                    </li>
                    <li class="flex items-start">
                        <div class="bg-white bg-opacity-20 p-1 rounded-full mr-3 mt-1">
                            <i class="fas fa-check text-xs"></i>
                        </div>
                        <span>理解它们的区别有助于选择<strong>合适的多任务处理策略</strong></span>
                    </li>
                </ul>
            </div>
        </div>
    </section>

    <!-- Footer -->
    <footer class="bg-gray-900 text-white py-12 px-4">
        <div class="container mx-auto max-w-6xl">
            <div class="text-center">
                <h3 class="text-xl font-bold mb-2">技术小馆</h3>
                <a href="http://www.yuque.com/jtostring" class="text-gray-400 hover:text-white transition-colors">
                    www.yuque.com/jtostring
                </a>
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>